﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Flowmanage_WorkFlow : UserPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Page_Initial();
        }
    }

    private void Page_Initial()
    {
        string sqlStr = "SELECT flow_short,flow_name,if_valid FROM u_workflow_t ORDER BY if_valid";
        FlowList.DataSource = OracleHelper.ExecuteDataSet(sqlStr, CommandType.Text, null);
        FlowList.DataBind();
    }

    protected void UserList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string sqlStr = "UPDATE u_workflow_t SET if_valid = DECODE(if_valid,'Y','N','Y') WHERE flow_short = :flow_short";
        OracleParameter[] _params = {
                    new OracleParameter(":flow_short",OracleType.VarChar,3)
            };
        _params[0].Value = e.CommandArgument.ToString();
        int res = OracleHelper.ExecuteNonQuery(sqlStr, CommandType.Text, _params);
        if (res > 0)
        {
            Page_Initial();
            JQueryAlert("状态切换成功！");
        }
    }

    protected void BtnCreate_Click(object sender, EventArgs e)
    {
        string sqlStr = "INSERT INTO u_workflow_t(flow_short,flow_name) VALUES(:flow_short,:flow_name)";
        OracleParameter[] _params = {
                    new OracleParameter(":flow_short",OracleType.VarChar,3),
                    new OracleParameter(":flow_name",OracleType.NVarChar,12)
            };
        _params[0].Value = Flow_Short_A.Text.Trim();
        _params[1].Value = Flow_Name_A.Text.Trim();
        int res = OracleHelper.ExecuteNonQuery(sqlStr, CommandType.Text, _params);
        if (res > 0)
        {
            Page_Initial();
            Flow_Name_A.Text = "";
            Flow_Short_A.Text = "";
            JQueryAlert("流程新建成功！");
        }
    }
}
